{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 注意：本文件中所有nn使用torch实现（个人对torch更熟悉）\n",
    "## 准备数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "import torch\n",
    "import torch.nn as nn\n",
    "import torch.optim as optim\n",
    "from torchvision import datasets, transforms\n",
    "from torch.utils.data import DataLoader\n",
    "import numpy as np\n",
    "\n",
    "# 设备配置\n",
    "device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')\n",
    "\n",
    "# 准备数据\n",
    "transform = transforms.Compose([\n",
    "    transforms.ToTensor(),\n",
    "    transforms.Normalize((0.1307,), (0.3081,))\n",
    "])\n",
    "\n",
    "train_dataset = datasets.MNIST(root='./data', train=True, download=True, transform=transform)\n",
    "test_dataset = datasets.MNIST(root='./data', train=False, transform=transform)\n",
    "\n",
    "train_loader = DataLoader(dataset=train_dataset, batch_size=64, shuffle=True)\n",
    "test_loader = DataLoader(dataset=test_dataset, batch_size=1000, shuffle=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 建立模型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "class FNN(nn.Module):\n",
    "    def __init__(self):\n",
    "        super(FNN, self).__init__()\n",
    "        self.fc1 = nn.Linear(28*28, 100)\n",
    "        self.relu = nn.ReLU()\n",
    "        self.fc2 = nn.Linear(100, 10)\n",
    "        self.log_softmax = nn.LogSoftmax(dim=1)\n",
    "\n",
    "    def forward(self, x):\n",
    "        x = x.view(-1, 28*28)\n",
    "        x = self.fc1(x)\n",
    "        x = self.relu(x)\n",
    "        x = self.fc2(x)\n",
    "        return self.log_softmax(x)\n",
    "\n",
    "model = FNN().to(device)\n",
    "criterion = nn.NLLLoss()  # 负对数似然损失，配合LogSoftmax\n",
    "optimizer = optim.SGD(model.parameters(), lr=1e-5)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 写训练和测试函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 训练函数\n",
    "def train(model, device, train_loader, optimizer, epoch):\n",
    "    model.train()\n",
    "    for batch_idx, (data, target) in enumerate(train_loader):\n",
    "        data, target = data.to(device), target.to(device)\n",
    "        optimizer.zero_grad()\n",
    "        output = model(data)\n",
    "        loss = criterion(output, target)\n",
    "        loss.backward()\n",
    "        optimizer.step()\n",
    "        \n",
    "        if batch_idx % 100 == 0:\n",
    "            print(f'Train Epoch: {epoch} [{batch_idx * len(data)}/{len(train_loader.dataset)} '\n",
    "                  f'({100. * batch_idx / len(train_loader):.0f}%)]\\tLoss: {loss.item():.6f}')\n",
    "\n",
    "# 测试函数\n",
    "def test(model, device, test_loader):\n",
    "    model.eval()\n",
    "    test_loss = 0\n",
    "    correct = 0\n",
    "    with torch.no_grad():\n",
    "        for data, target in test_loader:\n",
    "            data, target = data.to(device), target.to(device)\n",
    "            output = model(data)\n",
    "            test_loss += criterion(output, target).item()\n",
    "            pred = output.argmax(dim=1, keepdim=True)\n",
    "            correct += pred.eq(target.view_as(pred)).sum().item()\n",
    "    \n",
    "    test_loss /= len(test_loader.dataset)\n",
    "    accuracy = 100. * correct / len(test_loader.dataset)\n",
    "    print(f'\\nTest set: Average loss: {test_loss:.4f}, Accuracy: {correct}/{len(test_loader.dataset)} ({accuracy:.0f}%)\\n')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 实际训练"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Train Epoch: 1 [0/60000 (0%)]\tLoss: 2.375385\n",
      "Train Epoch: 1 [6400/60000 (11%)]\tLoss: 2.352809\n",
      "Train Epoch: 1 [12800/60000 (21%)]\tLoss: 2.391284\n",
      "Train Epoch: 1 [19200/60000 (32%)]\tLoss: 2.426278\n",
      "Train Epoch: 1 [25600/60000 (43%)]\tLoss: 2.356529\n",
      "Train Epoch: 1 [32000/60000 (53%)]\tLoss: 2.364251\n",
      "Train Epoch: 1 [38400/60000 (64%)]\tLoss: 2.339247\n",
      "Train Epoch: 1 [44800/60000 (75%)]\tLoss: 2.367275\n",
      "Train Epoch: 1 [51200/60000 (85%)]\tLoss: 2.331182\n",
      "Train Epoch: 1 [57600/60000 (96%)]\tLoss: 2.377909\n",
      "\n",
      "Test set: Average loss: 0.0024, Accuracy: 966/10000 (10%)\n",
      "\n",
      "Train Epoch: 2 [0/60000 (0%)]\tLoss: 2.342038\n",
      "Train Epoch: 2 [6400/60000 (11%)]\tLoss: 2.315703\n",
      "Train Epoch: 2 [12800/60000 (21%)]\tLoss: 2.341734\n",
      "Train Epoch: 2 [19200/60000 (32%)]\tLoss: 2.363348\n",
      "Train Epoch: 2 [25600/60000 (43%)]\tLoss: 2.399442\n",
      "Train Epoch: 2 [32000/60000 (53%)]\tLoss: 2.404377\n",
      "Train Epoch: 2 [38400/60000 (64%)]\tLoss: 2.359919\n",
      "Train Epoch: 2 [44800/60000 (75%)]\tLoss: 2.309893\n",
      "Train Epoch: 2 [51200/60000 (85%)]\tLoss: 2.322016\n",
      "Train Epoch: 2 [57600/60000 (96%)]\tLoss: 2.351577\n",
      "\n",
      "Test set: Average loss: 0.0023, Accuracy: 1005/10000 (10%)\n",
      "\n",
      "Train Epoch: 3 [0/60000 (0%)]\tLoss: 2.365209\n",
      "Train Epoch: 3 [6400/60000 (11%)]\tLoss: 2.346033\n",
      "Train Epoch: 3 [12800/60000 (21%)]\tLoss: 2.315654\n",
      "Train Epoch: 3 [19200/60000 (32%)]\tLoss: 2.261147\n",
      "Train Epoch: 3 [25600/60000 (43%)]\tLoss: 2.334274\n",
      "Train Epoch: 3 [32000/60000 (53%)]\tLoss: 2.340454\n",
      "Train Epoch: 3 [38400/60000 (64%)]\tLoss: 2.371738\n",
      "Train Epoch: 3 [44800/60000 (75%)]\tLoss: 2.310798\n",
      "Train Epoch: 3 [51200/60000 (85%)]\tLoss: 2.320374\n",
      "Train Epoch: 3 [57600/60000 (96%)]\tLoss: 2.274436\n",
      "\n",
      "Test set: Average loss: 0.0023, Accuracy: 1052/10000 (11%)\n",
      "\n",
      "Train Epoch: 4 [0/60000 (0%)]\tLoss: 2.326474\n",
      "Train Epoch: 4 [6400/60000 (11%)]\tLoss: 2.327874\n",
      "Train Epoch: 4 [12800/60000 (21%)]\tLoss: 2.260563\n",
      "Train Epoch: 4 [19200/60000 (32%)]\tLoss: 2.292558\n",
      "Train Epoch: 4 [25600/60000 (43%)]\tLoss: 2.386991\n",
      "Train Epoch: 4 [32000/60000 (53%)]\tLoss: 2.353769\n",
      "Train Epoch: 4 [38400/60000 (64%)]\tLoss: 2.319242\n",
      "Train Epoch: 4 [44800/60000 (75%)]\tLoss: 2.313763\n",
      "Train Epoch: 4 [51200/60000 (85%)]\tLoss: 2.300617\n",
      "Train Epoch: 4 [57600/60000 (96%)]\tLoss: 2.340341\n",
      "\n",
      "Test set: Average loss: 0.0023, Accuracy: 1125/10000 (11%)\n",
      "\n",
      "Train Epoch: 5 [0/60000 (0%)]\tLoss: 2.233761\n",
      "Train Epoch: 5 [6400/60000 (11%)]\tLoss: 2.334345\n",
      "Train Epoch: 5 [12800/60000 (21%)]\tLoss: 2.305829\n",
      "Train Epoch: 5 [19200/60000 (32%)]\tLoss: 2.355328\n",
      "Train Epoch: 5 [25600/60000 (43%)]\tLoss: 2.335813\n",
      "Train Epoch: 5 [32000/60000 (53%)]\tLoss: 2.341609\n",
      "Train Epoch: 5 [38400/60000 (64%)]\tLoss: 2.322885\n",
      "Train Epoch: 5 [44800/60000 (75%)]\tLoss: 2.295956\n",
      "Train Epoch: 5 [51200/60000 (85%)]\tLoss: 2.291589\n",
      "Train Epoch: 5 [57600/60000 (96%)]\tLoss: 2.311441\n",
      "\n",
      "Test set: Average loss: 0.0023, Accuracy: 1244/10000 (12%)\n",
      "\n",
      "Train Epoch: 6 [0/60000 (0%)]\tLoss: 2.260949\n",
      "Train Epoch: 6 [6400/60000 (11%)]\tLoss: 2.257696\n",
      "Train Epoch: 6 [12800/60000 (21%)]\tLoss: 2.261651\n",
      "Train Epoch: 6 [19200/60000 (32%)]\tLoss: 2.284395\n",
      "Train Epoch: 6 [25600/60000 (43%)]\tLoss: 2.323835\n",
      "Train Epoch: 6 [32000/60000 (53%)]\tLoss: 2.303147\n",
      "Train Epoch: 6 [38400/60000 (64%)]\tLoss: 2.295402\n",
      "Train Epoch: 6 [44800/60000 (75%)]\tLoss: 2.264142\n",
      "Train Epoch: 6 [51200/60000 (85%)]\tLoss: 2.242718\n",
      "Train Epoch: 6 [57600/60000 (96%)]\tLoss: 2.269199\n",
      "\n",
      "Test set: Average loss: 0.0023, Accuracy: 1369/10000 (14%)\n",
      "\n",
      "Train Epoch: 7 [0/60000 (0%)]\tLoss: 2.274099\n",
      "Train Epoch: 7 [6400/60000 (11%)]\tLoss: 2.224692\n",
      "Train Epoch: 7 [12800/60000 (21%)]\tLoss: 2.324763\n",
      "Train Epoch: 7 [19200/60000 (32%)]\tLoss: 2.242935\n",
      "Train Epoch: 7 [25600/60000 (43%)]\tLoss: 2.182495\n",
      "Train Epoch: 7 [32000/60000 (53%)]\tLoss: 2.230742\n",
      "Train Epoch: 7 [38400/60000 (64%)]\tLoss: 2.294121\n",
      "Train Epoch: 7 [44800/60000 (75%)]\tLoss: 2.286246\n",
      "Train Epoch: 7 [51200/60000 (85%)]\tLoss: 2.212725\n",
      "Train Epoch: 7 [57600/60000 (96%)]\tLoss: 2.220998\n",
      "\n",
      "Test set: Average loss: 0.0023, Accuracy: 1521/10000 (15%)\n",
      "\n",
      "Train Epoch: 8 [0/60000 (0%)]\tLoss: 2.261775\n",
      "Train Epoch: 8 [6400/60000 (11%)]\tLoss: 2.239890\n",
      "Train Epoch: 8 [12800/60000 (21%)]\tLoss: 2.270524\n",
      "Train Epoch: 8 [19200/60000 (32%)]\tLoss: 2.247353\n",
      "Train Epoch: 8 [25600/60000 (43%)]\tLoss: 2.224849\n",
      "Train Epoch: 8 [32000/60000 (53%)]\tLoss: 2.258317\n",
      "Train Epoch: 8 [38400/60000 (64%)]\tLoss: 2.199104\n",
      "Train Epoch: 8 [44800/60000 (75%)]\tLoss: 2.274176\n",
      "Train Epoch: 8 [51200/60000 (85%)]\tLoss: 2.303936\n",
      "Train Epoch: 8 [57600/60000 (96%)]\tLoss: 2.227157\n",
      "\n",
      "Test set: Average loss: 0.0022, Accuracy: 1689/10000 (17%)\n",
      "\n",
      "Train Epoch: 9 [0/60000 (0%)]\tLoss: 2.282511\n",
      "Train Epoch: 9 [6400/60000 (11%)]\tLoss: 2.235286\n",
      "Train Epoch: 9 [12800/60000 (21%)]\tLoss: 2.209196\n",
      "Train Epoch: 9 [19200/60000 (32%)]\tLoss: 2.203300\n",
      "Train Epoch: 9 [25600/60000 (43%)]\tLoss: 2.238200\n",
      "Train Epoch: 9 [32000/60000 (53%)]\tLoss: 2.219163\n",
      "Train Epoch: 9 [38400/60000 (64%)]\tLoss: 2.191372\n",
      "Train Epoch: 9 [44800/60000 (75%)]\tLoss: 2.257487\n",
      "Train Epoch: 9 [51200/60000 (85%)]\tLoss: 2.269272\n",
      "Train Epoch: 9 [57600/60000 (96%)]\tLoss: 2.189682\n",
      "\n",
      "Test set: Average loss: 0.0022, Accuracy: 1858/10000 (19%)\n",
      "\n",
      "Train Epoch: 10 [0/60000 (0%)]\tLoss: 2.215794\n",
      "Train Epoch: 10 [6400/60000 (11%)]\tLoss: 2.207684\n",
      "Train Epoch: 10 [12800/60000 (21%)]\tLoss: 2.226695\n",
      "Train Epoch: 10 [19200/60000 (32%)]\tLoss: 2.246706\n",
      "Train Epoch: 10 [25600/60000 (43%)]\tLoss: 2.216501\n",
      "Train Epoch: 10 [32000/60000 (53%)]\tLoss: 2.259116\n",
      "Train Epoch: 10 [38400/60000 (64%)]\tLoss: 2.215643\n",
      "Train Epoch: 10 [44800/60000 (75%)]\tLoss: 2.219084\n",
      "Train Epoch: 10 [51200/60000 (85%)]\tLoss: 2.229924\n",
      "Train Epoch: 10 [57600/60000 (96%)]\tLoss: 2.233519\n",
      "\n",
      "Test set: Average loss: 0.0022, Accuracy: 2047/10000 (20%)\n",
      "\n",
      "Train Epoch: 11 [0/60000 (0%)]\tLoss: 2.164814\n",
      "Train Epoch: 11 [6400/60000 (11%)]\tLoss: 2.225909\n",
      "Train Epoch: 11 [12800/60000 (21%)]\tLoss: 2.218965\n",
      "Train Epoch: 11 [19200/60000 (32%)]\tLoss: 2.207443\n",
      "Train Epoch: 11 [25600/60000 (43%)]\tLoss: 2.175786\n",
      "Train Epoch: 11 [32000/60000 (53%)]\tLoss: 2.147631\n",
      "Train Epoch: 11 [38400/60000 (64%)]\tLoss: 2.179867\n",
      "Train Epoch: 11 [44800/60000 (75%)]\tLoss: 2.214391\n",
      "Train Epoch: 11 [51200/60000 (85%)]\tLoss: 2.202777\n",
      "Train Epoch: 11 [57600/60000 (96%)]\tLoss: 2.202976\n",
      "\n",
      "Test set: Average loss: 0.0022, Accuracy: 2256/10000 (23%)\n",
      "\n",
      "Train Epoch: 12 [0/60000 (0%)]\tLoss: 2.165561\n",
      "Train Epoch: 12 [6400/60000 (11%)]\tLoss: 2.163993\n",
      "Train Epoch: 12 [12800/60000 (21%)]\tLoss: 2.213930\n",
      "Train Epoch: 12 [19200/60000 (32%)]\tLoss: 2.187385\n",
      "Train Epoch: 12 [25600/60000 (43%)]\tLoss: 2.128413\n",
      "Train Epoch: 12 [32000/60000 (53%)]\tLoss: 2.196188\n",
      "Train Epoch: 12 [38400/60000 (64%)]\tLoss: 2.173119\n",
      "Train Epoch: 12 [44800/60000 (75%)]\tLoss: 2.153658\n",
      "Train Epoch: 12 [51200/60000 (85%)]\tLoss: 2.173354\n",
      "Train Epoch: 12 [57600/60000 (96%)]\tLoss: 2.160592\n",
      "\n",
      "Test set: Average loss: 0.0022, Accuracy: 2472/10000 (25%)\n",
      "\n",
      "Train Epoch: 13 [0/60000 (0%)]\tLoss: 2.164423\n",
      "Train Epoch: 13 [6400/60000 (11%)]\tLoss: 2.137593\n",
      "Train Epoch: 13 [12800/60000 (21%)]\tLoss: 2.156336\n",
      "Train Epoch: 13 [19200/60000 (32%)]\tLoss: 2.167022\n",
      "Train Epoch: 13 [25600/60000 (43%)]\tLoss: 2.205620\n",
      "Train Epoch: 13 [32000/60000 (53%)]\tLoss: 2.171300\n",
      "Train Epoch: 13 [38400/60000 (64%)]\tLoss: 2.207480\n",
      "Train Epoch: 13 [44800/60000 (75%)]\tLoss: 2.157070\n",
      "Train Epoch: 13 [51200/60000 (85%)]\tLoss: 2.182348\n",
      "Train Epoch: 13 [57600/60000 (96%)]\tLoss: 2.174370\n",
      "\n",
      "Test set: Average loss: 0.0022, Accuracy: 2669/10000 (27%)\n",
      "\n",
      "Train Epoch: 14 [0/60000 (0%)]\tLoss: 2.160630\n",
      "Train Epoch: 14 [6400/60000 (11%)]\tLoss: 2.131768\n",
      "Train Epoch: 14 [12800/60000 (21%)]\tLoss: 2.130057\n",
      "Train Epoch: 14 [19200/60000 (32%)]\tLoss: 2.104207\n",
      "Train Epoch: 14 [25600/60000 (43%)]\tLoss: 2.179658\n",
      "Train Epoch: 14 [32000/60000 (53%)]\tLoss: 2.198667\n",
      "Train Epoch: 14 [38400/60000 (64%)]\tLoss: 2.151943\n",
      "Train Epoch: 14 [44800/60000 (75%)]\tLoss: 2.141824\n",
      "Train Epoch: 14 [51200/60000 (85%)]\tLoss: 2.132573\n",
      "Train Epoch: 14 [57600/60000 (96%)]\tLoss: 2.136622\n",
      "\n",
      "Test set: Average loss: 0.0022, Accuracy: 2879/10000 (29%)\n",
      "\n",
      "Train Epoch: 15 [0/60000 (0%)]\tLoss: 2.193677\n",
      "Train Epoch: 15 [6400/60000 (11%)]\tLoss: 2.182278\n",
      "Train Epoch: 15 [12800/60000 (21%)]\tLoss: 2.148970\n",
      "Train Epoch: 15 [19200/60000 (32%)]\tLoss: 2.127136\n",
      "Train Epoch: 15 [25600/60000 (43%)]\tLoss: 2.158114\n",
      "Train Epoch: 15 [32000/60000 (53%)]\tLoss: 2.154790\n",
      "Train Epoch: 15 [38400/60000 (64%)]\tLoss: 2.176646\n",
      "Train Epoch: 15 [44800/60000 (75%)]\tLoss: 2.174230\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Train Epoch: 15 [51200/60000 (85%)]\tLoss: 2.106243\n",
      "Train Epoch: 15 [57600/60000 (96%)]\tLoss: 2.125760\n",
      "\n",
      "Test set: Average loss: 0.0021, Accuracy: 3081/10000 (31%)\n",
      "\n",
      "Train Epoch: 16 [0/60000 (0%)]\tLoss: 2.143304\n",
      "Train Epoch: 16 [6400/60000 (11%)]\tLoss: 2.158323\n",
      "Train Epoch: 16 [12800/60000 (21%)]\tLoss: 2.142863\n",
      "Train Epoch: 16 [19200/60000 (32%)]\tLoss: 2.165056\n",
      "Train Epoch: 16 [25600/60000 (43%)]\tLoss: 2.123098\n",
      "Train Epoch: 16 [32000/60000 (53%)]\tLoss: 2.139466\n",
      "Train Epoch: 16 [38400/60000 (64%)]\tLoss: 2.143799\n",
      "Train Epoch: 16 [44800/60000 (75%)]\tLoss: 2.072395\n",
      "Train Epoch: 16 [51200/60000 (85%)]\tLoss: 2.106961\n",
      "Train Epoch: 16 [57600/60000 (96%)]\tLoss: 2.109974\n",
      "\n",
      "Test set: Average loss: 0.0021, Accuracy: 3285/10000 (33%)\n",
      "\n",
      "Train Epoch: 17 [0/60000 (0%)]\tLoss: 2.091527\n",
      "Train Epoch: 17 [6400/60000 (11%)]\tLoss: 2.179228\n",
      "Train Epoch: 17 [12800/60000 (21%)]\tLoss: 2.142626\n",
      "Train Epoch: 17 [19200/60000 (32%)]\tLoss: 2.106802\n",
      "Train Epoch: 17 [25600/60000 (43%)]\tLoss: 2.117981\n",
      "Train Epoch: 17 [32000/60000 (53%)]\tLoss: 2.152236\n",
      "Train Epoch: 17 [38400/60000 (64%)]\tLoss: 2.088054\n",
      "Train Epoch: 17 [44800/60000 (75%)]\tLoss: 2.116301\n",
      "Train Epoch: 17 [51200/60000 (85%)]\tLoss: 2.150448\n",
      "Train Epoch: 17 [57600/60000 (96%)]\tLoss: 2.086951\n",
      "\n",
      "Test set: Average loss: 0.0021, Accuracy: 3450/10000 (34%)\n",
      "\n",
      "Train Epoch: 18 [0/60000 (0%)]\tLoss: 2.048844\n",
      "Train Epoch: 18 [6400/60000 (11%)]\tLoss: 2.109525\n",
      "Train Epoch: 18 [12800/60000 (21%)]\tLoss: 2.073742\n",
      "Train Epoch: 18 [19200/60000 (32%)]\tLoss: 2.069171\n",
      "Train Epoch: 18 [25600/60000 (43%)]\tLoss: 2.144507\n",
      "Train Epoch: 18 [32000/60000 (53%)]\tLoss: 2.123435\n",
      "Train Epoch: 18 [38400/60000 (64%)]\tLoss: 2.147595\n",
      "Train Epoch: 18 [44800/60000 (75%)]\tLoss: 2.111622\n",
      "Train Epoch: 18 [51200/60000 (85%)]\tLoss: 2.123233\n",
      "Train Epoch: 18 [57600/60000 (96%)]\tLoss: 2.161319\n",
      "\n",
      "Test set: Average loss: 0.0021, Accuracy: 3632/10000 (36%)\n",
      "\n",
      "Train Epoch: 19 [0/60000 (0%)]\tLoss: 2.131420\n",
      "Train Epoch: 19 [6400/60000 (11%)]\tLoss: 2.123415\n",
      "Train Epoch: 19 [12800/60000 (21%)]\tLoss: 2.135917\n",
      "Train Epoch: 19 [19200/60000 (32%)]\tLoss: 2.132527\n",
      "Train Epoch: 19 [25600/60000 (43%)]\tLoss: 2.086102\n",
      "Train Epoch: 19 [32000/60000 (53%)]\tLoss: 2.035047\n",
      "Train Epoch: 19 [38400/60000 (64%)]\tLoss: 2.100679\n",
      "Train Epoch: 19 [44800/60000 (75%)]\tLoss: 2.090369\n",
      "Train Epoch: 19 [51200/60000 (85%)]\tLoss: 2.072741\n",
      "Train Epoch: 19 [57600/60000 (96%)]\tLoss: 2.091693\n",
      "\n",
      "Test set: Average loss: 0.0021, Accuracy: 3810/10000 (38%)\n",
      "\n",
      "Train Epoch: 20 [0/60000 (0%)]\tLoss: 2.056819\n",
      "Train Epoch: 20 [6400/60000 (11%)]\tLoss: 2.092636\n",
      "Train Epoch: 20 [12800/60000 (21%)]\tLoss: 2.059658\n",
      "Train Epoch: 20 [19200/60000 (32%)]\tLoss: 2.144801\n",
      "Train Epoch: 20 [25600/60000 (43%)]\tLoss: 2.089562\n",
      "Train Epoch: 20 [32000/60000 (53%)]\tLoss: 2.075137\n",
      "Train Epoch: 20 [38400/60000 (64%)]\tLoss: 2.021868\n",
      "Train Epoch: 20 [44800/60000 (75%)]\tLoss: 2.084417\n",
      "Train Epoch: 20 [51200/60000 (85%)]\tLoss: 2.135486\n",
      "Train Epoch: 20 [57600/60000 (96%)]\tLoss: 2.092088\n",
      "\n",
      "Test set: Average loss: 0.0021, Accuracy: 3994/10000 (40%)\n",
      "\n",
      "Train Epoch: 21 [0/60000 (0%)]\tLoss: 2.040947\n",
      "Train Epoch: 21 [6400/60000 (11%)]\tLoss: 2.083721\n",
      "Train Epoch: 21 [12800/60000 (21%)]\tLoss: 2.123630\n",
      "Train Epoch: 21 [19200/60000 (32%)]\tLoss: 2.060534\n",
      "Train Epoch: 21 [25600/60000 (43%)]\tLoss: 2.065031\n",
      "Train Epoch: 21 [32000/60000 (53%)]\tLoss: 2.085120\n",
      "Train Epoch: 21 [38400/60000 (64%)]\tLoss: 2.045087\n",
      "Train Epoch: 21 [44800/60000 (75%)]\tLoss: 2.090020\n",
      "Train Epoch: 21 [51200/60000 (85%)]\tLoss: 2.062426\n",
      "Train Epoch: 21 [57600/60000 (96%)]\tLoss: 2.101892\n",
      "\n",
      "Test set: Average loss: 0.0021, Accuracy: 4162/10000 (42%)\n",
      "\n",
      "Train Epoch: 22 [0/60000 (0%)]\tLoss: 2.128086\n",
      "Train Epoch: 22 [6400/60000 (11%)]\tLoss: 2.089170\n",
      "Train Epoch: 22 [12800/60000 (21%)]\tLoss: 2.058502\n",
      "Train Epoch: 22 [19200/60000 (32%)]\tLoss: 1.990654\n",
      "Train Epoch: 22 [25600/60000 (43%)]\tLoss: 2.117738\n",
      "Train Epoch: 22 [32000/60000 (53%)]\tLoss: 2.021330\n",
      "Train Epoch: 22 [38400/60000 (64%)]\tLoss: 2.070933\n",
      "Train Epoch: 22 [44800/60000 (75%)]\tLoss: 2.065346\n",
      "Train Epoch: 22 [51200/60000 (85%)]\tLoss: 2.033642\n",
      "Train Epoch: 22 [57600/60000 (96%)]\tLoss: 2.049329\n",
      "\n",
      "Test set: Average loss: 0.0020, Accuracy: 4316/10000 (43%)\n",
      "\n",
      "Train Epoch: 23 [0/60000 (0%)]\tLoss: 2.050869\n",
      "Train Epoch: 23 [6400/60000 (11%)]\tLoss: 2.042577\n",
      "Train Epoch: 23 [12800/60000 (21%)]\tLoss: 2.059217\n",
      "Train Epoch: 23 [19200/60000 (32%)]\tLoss: 2.046569\n",
      "Train Epoch: 23 [25600/60000 (43%)]\tLoss: 2.032856\n",
      "Train Epoch: 23 [32000/60000 (53%)]\tLoss: 2.058115\n",
      "Train Epoch: 23 [38400/60000 (64%)]\tLoss: 2.032813\n",
      "Train Epoch: 23 [44800/60000 (75%)]\tLoss: 2.005415\n",
      "Train Epoch: 23 [51200/60000 (85%)]\tLoss: 2.040505\n",
      "Train Epoch: 23 [57600/60000 (96%)]\tLoss: 2.002083\n",
      "\n",
      "Test set: Average loss: 0.0020, Accuracy: 4451/10000 (45%)\n",
      "\n",
      "Train Epoch: 24 [0/60000 (0%)]\tLoss: 1.978166\n",
      "Train Epoch: 24 [6400/60000 (11%)]\tLoss: 2.023317\n",
      "Train Epoch: 24 [12800/60000 (21%)]\tLoss: 2.013407\n",
      "Train Epoch: 24 [19200/60000 (32%)]\tLoss: 2.015177\n",
      "Train Epoch: 24 [25600/60000 (43%)]\tLoss: 2.022592\n",
      "Train Epoch: 24 [32000/60000 (53%)]\tLoss: 1.972998\n",
      "Train Epoch: 24 [38400/60000 (64%)]\tLoss: 2.032461\n",
      "Train Epoch: 24 [44800/60000 (75%)]\tLoss: 1.985039\n",
      "Train Epoch: 24 [51200/60000 (85%)]\tLoss: 2.063177\n",
      "Train Epoch: 24 [57600/60000 (96%)]\tLoss: 2.029038\n",
      "\n",
      "Test set: Average loss: 0.0020, Accuracy: 4565/10000 (46%)\n",
      "\n",
      "Train Epoch: 25 [0/60000 (0%)]\tLoss: 2.001596\n",
      "Train Epoch: 25 [6400/60000 (11%)]\tLoss: 1.958173\n",
      "Train Epoch: 25 [12800/60000 (21%)]\tLoss: 2.053118\n",
      "Train Epoch: 25 [19200/60000 (32%)]\tLoss: 1.984095\n",
      "Train Epoch: 25 [25600/60000 (43%)]\tLoss: 1.950016\n",
      "Train Epoch: 25 [32000/60000 (53%)]\tLoss: 1.957588\n",
      "Train Epoch: 25 [38400/60000 (64%)]\tLoss: 2.016711\n",
      "Train Epoch: 25 [44800/60000 (75%)]\tLoss: 2.035897\n",
      "Train Epoch: 25 [51200/60000 (85%)]\tLoss: 1.931078\n",
      "Train Epoch: 25 [57600/60000 (96%)]\tLoss: 1.959624\n",
      "\n",
      "Test set: Average loss: 0.0020, Accuracy: 4658/10000 (47%)\n",
      "\n",
      "Train Epoch: 26 [0/60000 (0%)]\tLoss: 1.943793\n",
      "Train Epoch: 26 [6400/60000 (11%)]\tLoss: 1.986864\n",
      "Train Epoch: 26 [12800/60000 (21%)]\tLoss: 1.978180\n",
      "Train Epoch: 26 [19200/60000 (32%)]\tLoss: 1.960448\n",
      "Train Epoch: 26 [25600/60000 (43%)]\tLoss: 1.937686\n",
      "Train Epoch: 26 [32000/60000 (53%)]\tLoss: 1.984461\n",
      "Train Epoch: 26 [38400/60000 (64%)]\tLoss: 2.020133\n",
      "Train Epoch: 26 [44800/60000 (75%)]\tLoss: 1.992932\n",
      "Train Epoch: 26 [51200/60000 (85%)]\tLoss: 1.959979\n",
      "Train Epoch: 26 [57600/60000 (96%)]\tLoss: 1.959879\n",
      "\n",
      "Test set: Average loss: 0.0020, Accuracy: 4775/10000 (48%)\n",
      "\n",
      "Train Epoch: 27 [0/60000 (0%)]\tLoss: 1.976107\n",
      "Train Epoch: 27 [6400/60000 (11%)]\tLoss: 1.983628\n",
      "Train Epoch: 27 [12800/60000 (21%)]\tLoss: 1.953217\n",
      "Train Epoch: 27 [19200/60000 (32%)]\tLoss: 1.913515\n",
      "Train Epoch: 27 [25600/60000 (43%)]\tLoss: 2.020640\n",
      "Train Epoch: 27 [32000/60000 (53%)]\tLoss: 1.985071\n",
      "Train Epoch: 27 [38400/60000 (64%)]\tLoss: 1.971654\n",
      "Train Epoch: 27 [44800/60000 (75%)]\tLoss: 1.997659\n",
      "Train Epoch: 27 [51200/60000 (85%)]\tLoss: 2.018650\n",
      "Train Epoch: 27 [57600/60000 (96%)]\tLoss: 1.998766\n",
      "\n",
      "Test set: Average loss: 0.0020, Accuracy: 4885/10000 (49%)\n",
      "\n",
      "Train Epoch: 28 [0/60000 (0%)]\tLoss: 1.894195\n",
      "Train Epoch: 28 [6400/60000 (11%)]\tLoss: 1.949932\n",
      "Train Epoch: 28 [12800/60000 (21%)]\tLoss: 1.939532\n",
      "Train Epoch: 28 [19200/60000 (32%)]\tLoss: 1.937368\n",
      "Train Epoch: 28 [25600/60000 (43%)]\tLoss: 1.925522\n",
      "Train Epoch: 28 [32000/60000 (53%)]\tLoss: 1.981587\n",
      "Train Epoch: 28 [38400/60000 (64%)]\tLoss: 1.963600\n",
      "Train Epoch: 28 [44800/60000 (75%)]\tLoss: 1.973570\n",
      "Train Epoch: 28 [51200/60000 (85%)]\tLoss: 1.975002\n",
      "Train Epoch: 28 [57600/60000 (96%)]\tLoss: 2.016416\n",
      "\n",
      "Test set: Average loss: 0.0019, Accuracy: 4996/10000 (50%)\n",
      "\n",
      "Train Epoch: 29 [0/60000 (0%)]\tLoss: 1.906934\n",
      "Train Epoch: 29 [6400/60000 (11%)]\tLoss: 1.950607\n",
      "Train Epoch: 29 [12800/60000 (21%)]\tLoss: 1.930861\n",
      "Train Epoch: 29 [19200/60000 (32%)]\tLoss: 1.991724\n",
      "Train Epoch: 29 [25600/60000 (43%)]\tLoss: 1.964336\n",
      "Train Epoch: 29 [32000/60000 (53%)]\tLoss: 1.938820\n",
      "Train Epoch: 29 [38400/60000 (64%)]\tLoss: 1.940248\n",
      "Train Epoch: 29 [44800/60000 (75%)]\tLoss: 1.916106\n",
      "Train Epoch: 29 [51200/60000 (85%)]\tLoss: 1.938218\n",
      "Train Epoch: 29 [57600/60000 (96%)]\tLoss: 1.999050\n",
      "\n",
      "Test set: Average loss: 0.0019, Accuracy: 5076/10000 (51%)\n",
      "\n",
      "Train Epoch: 30 [0/60000 (0%)]\tLoss: 1.939040\n",
      "Train Epoch: 30 [6400/60000 (11%)]\tLoss: 1.930463\n",
      "Train Epoch: 30 [12800/60000 (21%)]\tLoss: 1.899865\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Train Epoch: 30 [19200/60000 (32%)]\tLoss: 1.967823\n",
      "Train Epoch: 30 [25600/60000 (43%)]\tLoss: 1.943847\n",
      "Train Epoch: 30 [32000/60000 (53%)]\tLoss: 1.918602\n",
      "Train Epoch: 30 [38400/60000 (64%)]\tLoss: 1.916362\n",
      "Train Epoch: 30 [44800/60000 (75%)]\tLoss: 1.916871\n",
      "Train Epoch: 30 [51200/60000 (85%)]\tLoss: 1.915438\n",
      "Train Epoch: 30 [57600/60000 (96%)]\tLoss: 1.933088\n",
      "\n",
      "Test set: Average loss: 0.0019, Accuracy: 5157/10000 (52%)\n",
      "\n",
      "Train Epoch: 31 [0/60000 (0%)]\tLoss: 1.952710\n",
      "Train Epoch: 31 [6400/60000 (11%)]\tLoss: 1.881994\n",
      "Train Epoch: 31 [12800/60000 (21%)]\tLoss: 1.926744\n",
      "Train Epoch: 31 [19200/60000 (32%)]\tLoss: 1.846857\n",
      "Train Epoch: 31 [25600/60000 (43%)]\tLoss: 1.831645\n",
      "Train Epoch: 31 [32000/60000 (53%)]\tLoss: 1.953084\n",
      "Train Epoch: 31 [38400/60000 (64%)]\tLoss: 1.919778\n",
      "Train Epoch: 31 [44800/60000 (75%)]\tLoss: 1.910091\n",
      "Train Epoch: 31 [51200/60000 (85%)]\tLoss: 1.947654\n",
      "Train Epoch: 31 [57600/60000 (96%)]\tLoss: 1.913446\n",
      "\n",
      "Test set: Average loss: 0.0019, Accuracy: 5252/10000 (53%)\n",
      "\n",
      "Train Epoch: 32 [0/60000 (0%)]\tLoss: 1.886461\n",
      "Train Epoch: 32 [6400/60000 (11%)]\tLoss: 1.856523\n",
      "Train Epoch: 32 [12800/60000 (21%)]\tLoss: 1.902911\n",
      "Train Epoch: 32 [19200/60000 (32%)]\tLoss: 1.909973\n",
      "Train Epoch: 32 [25600/60000 (43%)]\tLoss: 1.865460\n",
      "Train Epoch: 32 [32000/60000 (53%)]\tLoss: 1.952369\n",
      "Train Epoch: 32 [38400/60000 (64%)]\tLoss: 1.861819\n",
      "Train Epoch: 32 [44800/60000 (75%)]\tLoss: 1.921894\n",
      "Train Epoch: 32 [51200/60000 (85%)]\tLoss: 1.965616\n",
      "Train Epoch: 32 [57600/60000 (96%)]\tLoss: 1.840960\n",
      "\n",
      "Test set: Average loss: 0.0019, Accuracy: 5318/10000 (53%)\n",
      "\n",
      "Train Epoch: 33 [0/60000 (0%)]\tLoss: 1.927751\n",
      "Train Epoch: 33 [6400/60000 (11%)]\tLoss: 1.852608\n",
      "Train Epoch: 33 [12800/60000 (21%)]\tLoss: 1.871903\n",
      "Train Epoch: 33 [19200/60000 (32%)]\tLoss: 1.861244\n",
      "Train Epoch: 33 [25600/60000 (43%)]\tLoss: 1.903936\n",
      "Train Epoch: 33 [32000/60000 (53%)]\tLoss: 1.933772\n",
      "Train Epoch: 33 [38400/60000 (64%)]\tLoss: 1.886303\n",
      "Train Epoch: 33 [44800/60000 (75%)]\tLoss: 1.933098\n",
      "Train Epoch: 33 [51200/60000 (85%)]\tLoss: 1.954329\n",
      "Train Epoch: 33 [57600/60000 (96%)]\tLoss: 1.878695\n",
      "\n",
      "Test set: Average loss: 0.0019, Accuracy: 5389/10000 (54%)\n",
      "\n",
      "Train Epoch: 34 [0/60000 (0%)]\tLoss: 1.917945\n",
      "Train Epoch: 34 [6400/60000 (11%)]\tLoss: 1.881107\n",
      "Train Epoch: 34 [12800/60000 (21%)]\tLoss: 1.820117\n",
      "Train Epoch: 34 [19200/60000 (32%)]\tLoss: 1.872254\n",
      "Train Epoch: 34 [25600/60000 (43%)]\tLoss: 1.899806\n",
      "Train Epoch: 34 [32000/60000 (53%)]\tLoss: 1.849449\n",
      "Train Epoch: 34 [38400/60000 (64%)]\tLoss: 1.839423\n",
      "Train Epoch: 34 [44800/60000 (75%)]\tLoss: 1.836105\n",
      "Train Epoch: 34 [51200/60000 (85%)]\tLoss: 1.814855\n",
      "Train Epoch: 34 [57600/60000 (96%)]\tLoss: 1.893891\n",
      "\n",
      "Test set: Average loss: 0.0019, Accuracy: 5461/10000 (55%)\n",
      "\n",
      "Train Epoch: 35 [0/60000 (0%)]\tLoss: 1.871916\n",
      "Train Epoch: 35 [6400/60000 (11%)]\tLoss: 1.890953\n",
      "Train Epoch: 35 [12800/60000 (21%)]\tLoss: 1.891922\n",
      "Train Epoch: 35 [19200/60000 (32%)]\tLoss: 1.865350\n",
      "Train Epoch: 35 [25600/60000 (43%)]\tLoss: 1.827030\n",
      "Train Epoch: 35 [32000/60000 (53%)]\tLoss: 1.834467\n",
      "Train Epoch: 35 [38400/60000 (64%)]\tLoss: 1.841160\n",
      "Train Epoch: 35 [44800/60000 (75%)]\tLoss: 1.899688\n",
      "Train Epoch: 35 [51200/60000 (85%)]\tLoss: 1.836319\n",
      "Train Epoch: 35 [57600/60000 (96%)]\tLoss: 1.900810\n",
      "\n",
      "Test set: Average loss: 0.0018, Accuracy: 5532/10000 (55%)\n",
      "\n",
      "Train Epoch: 36 [0/60000 (0%)]\tLoss: 1.852776\n",
      "Train Epoch: 36 [6400/60000 (11%)]\tLoss: 1.799451\n",
      "Train Epoch: 36 [12800/60000 (21%)]\tLoss: 1.888904\n",
      "Train Epoch: 36 [19200/60000 (32%)]\tLoss: 1.839676\n",
      "Train Epoch: 36 [25600/60000 (43%)]\tLoss: 1.868157\n",
      "Train Epoch: 36 [32000/60000 (53%)]\tLoss: 1.778465\n",
      "Train Epoch: 36 [38400/60000 (64%)]\tLoss: 1.889851\n",
      "Train Epoch: 36 [44800/60000 (75%)]\tLoss: 1.839511\n",
      "Train Epoch: 36 [51200/60000 (85%)]\tLoss: 1.801070\n",
      "Train Epoch: 36 [57600/60000 (96%)]\tLoss: 1.794808\n",
      "\n",
      "Test set: Average loss: 0.0018, Accuracy: 5610/10000 (56%)\n",
      "\n",
      "Train Epoch: 37 [0/60000 (0%)]\tLoss: 1.823289\n",
      "Train Epoch: 37 [6400/60000 (11%)]\tLoss: 1.763194\n",
      "Train Epoch: 37 [12800/60000 (21%)]\tLoss: 1.846201\n",
      "Train Epoch: 37 [19200/60000 (32%)]\tLoss: 1.785123\n",
      "Train Epoch: 37 [25600/60000 (43%)]\tLoss: 1.755478\n",
      "Train Epoch: 37 [32000/60000 (53%)]\tLoss: 1.840811\n",
      "Train Epoch: 37 [38400/60000 (64%)]\tLoss: 1.757922\n",
      "Train Epoch: 37 [44800/60000 (75%)]\tLoss: 1.862358\n",
      "Train Epoch: 37 [51200/60000 (85%)]\tLoss: 1.868520\n",
      "Train Epoch: 37 [57600/60000 (96%)]\tLoss: 1.833449\n",
      "\n",
      "Test set: Average loss: 0.0018, Accuracy: 5670/10000 (57%)\n",
      "\n",
      "Train Epoch: 38 [0/60000 (0%)]\tLoss: 1.834291\n",
      "Train Epoch: 38 [6400/60000 (11%)]\tLoss: 1.867867\n",
      "Train Epoch: 38 [12800/60000 (21%)]\tLoss: 1.786341\n",
      "Train Epoch: 38 [19200/60000 (32%)]\tLoss: 1.800286\n",
      "Train Epoch: 38 [25600/60000 (43%)]\tLoss: 1.845351\n",
      "Train Epoch: 38 [32000/60000 (53%)]\tLoss: 1.852789\n",
      "Train Epoch: 38 [38400/60000 (64%)]\tLoss: 1.837481\n",
      "Train Epoch: 38 [44800/60000 (75%)]\tLoss: 1.712544\n",
      "Train Epoch: 38 [51200/60000 (85%)]\tLoss: 1.856415\n",
      "Train Epoch: 38 [57600/60000 (96%)]\tLoss: 1.886693\n",
      "\n",
      "Test set: Average loss: 0.0018, Accuracy: 5727/10000 (57%)\n",
      "\n",
      "Train Epoch: 39 [0/60000 (0%)]\tLoss: 1.803561\n",
      "Train Epoch: 39 [6400/60000 (11%)]\tLoss: 1.822622\n",
      "Train Epoch: 39 [12800/60000 (21%)]\tLoss: 1.774138\n",
      "Train Epoch: 39 [19200/60000 (32%)]\tLoss: 1.795973\n",
      "Train Epoch: 39 [25600/60000 (43%)]\tLoss: 1.798650\n",
      "Train Epoch: 39 [32000/60000 (53%)]\tLoss: 1.854044\n",
      "Train Epoch: 39 [38400/60000 (64%)]\tLoss: 1.808472\n",
      "Train Epoch: 39 [44800/60000 (75%)]\tLoss: 1.886272\n",
      "Train Epoch: 39 [51200/60000 (85%)]\tLoss: 1.776421\n",
      "Train Epoch: 39 [57600/60000 (96%)]\tLoss: 1.725371\n",
      "\n",
      "Test set: Average loss: 0.0018, Accuracy: 5799/10000 (58%)\n",
      "\n",
      "Train Epoch: 40 [0/60000 (0%)]\tLoss: 1.791064\n",
      "Train Epoch: 40 [6400/60000 (11%)]\tLoss: 1.772249\n",
      "Train Epoch: 40 [12800/60000 (21%)]\tLoss: 1.827745\n",
      "Train Epoch: 40 [19200/60000 (32%)]\tLoss: 1.753315\n",
      "Train Epoch: 40 [25600/60000 (43%)]\tLoss: 1.849121\n",
      "Train Epoch: 40 [32000/60000 (53%)]\tLoss: 1.758040\n",
      "Train Epoch: 40 [38400/60000 (64%)]\tLoss: 1.789274\n",
      "Train Epoch: 40 [44800/60000 (75%)]\tLoss: 1.766240\n",
      "Train Epoch: 40 [51200/60000 (85%)]\tLoss: 1.750289\n",
      "Train Epoch: 40 [57600/60000 (96%)]\tLoss: 1.762138\n",
      "\n",
      "Test set: Average loss: 0.0018, Accuracy: 5860/10000 (59%)\n",
      "\n",
      "Train Epoch: 41 [0/60000 (0%)]\tLoss: 1.797207\n",
      "Train Epoch: 41 [6400/60000 (11%)]\tLoss: 1.746591\n",
      "Train Epoch: 41 [12800/60000 (21%)]\tLoss: 1.759849\n",
      "Train Epoch: 41 [19200/60000 (32%)]\tLoss: 1.798953\n",
      "Train Epoch: 41 [25600/60000 (43%)]\tLoss: 1.739652\n",
      "Train Epoch: 41 [32000/60000 (53%)]\tLoss: 1.826217\n",
      "Train Epoch: 41 [38400/60000 (64%)]\tLoss: 1.756828\n",
      "Train Epoch: 41 [44800/60000 (75%)]\tLoss: 1.744683\n",
      "Train Epoch: 41 [51200/60000 (85%)]\tLoss: 1.777514\n",
      "Train Epoch: 41 [57600/60000 (96%)]\tLoss: 1.797254\n",
      "\n",
      "Test set: Average loss: 0.0018, Accuracy: 5920/10000 (59%)\n",
      "\n",
      "Train Epoch: 42 [0/60000 (0%)]\tLoss: 1.668274\n",
      "Train Epoch: 42 [6400/60000 (11%)]\tLoss: 1.691622\n",
      "Train Epoch: 42 [12800/60000 (21%)]\tLoss: 1.773122\n",
      "Train Epoch: 42 [19200/60000 (32%)]\tLoss: 1.802730\n",
      "Train Epoch: 42 [25600/60000 (43%)]\tLoss: 1.773002\n",
      "Train Epoch: 42 [32000/60000 (53%)]\tLoss: 1.848561\n",
      "Train Epoch: 42 [38400/60000 (64%)]\tLoss: 1.780577\n",
      "Train Epoch: 42 [44800/60000 (75%)]\tLoss: 1.770494\n",
      "Train Epoch: 42 [51200/60000 (85%)]\tLoss: 1.811604\n",
      "Train Epoch: 42 [57600/60000 (96%)]\tLoss: 1.774813\n",
      "\n",
      "Test set: Average loss: 0.0017, Accuracy: 5978/10000 (60%)\n",
      "\n",
      "Train Epoch: 43 [0/60000 (0%)]\tLoss: 1.755706\n",
      "Train Epoch: 43 [6400/60000 (11%)]\tLoss: 1.802451\n",
      "Train Epoch: 43 [12800/60000 (21%)]\tLoss: 1.676370\n",
      "Train Epoch: 43 [19200/60000 (32%)]\tLoss: 1.804384\n",
      "Train Epoch: 43 [25600/60000 (43%)]\tLoss: 1.760453\n",
      "Train Epoch: 43 [32000/60000 (53%)]\tLoss: 1.696728\n",
      "Train Epoch: 43 [38400/60000 (64%)]\tLoss: 1.711640\n",
      "Train Epoch: 43 [44800/60000 (75%)]\tLoss: 1.709184\n",
      "Train Epoch: 43 [51200/60000 (85%)]\tLoss: 1.710729\n",
      "Train Epoch: 43 [57600/60000 (96%)]\tLoss: 1.775520\n",
      "\n",
      "Test set: Average loss: 0.0017, Accuracy: 6041/10000 (60%)\n",
      "\n",
      "Train Epoch: 44 [0/60000 (0%)]\tLoss: 1.772151\n",
      "Train Epoch: 44 [6400/60000 (11%)]\tLoss: 1.704263\n",
      "Train Epoch: 44 [12800/60000 (21%)]\tLoss: 1.726934\n",
      "Train Epoch: 44 [19200/60000 (32%)]\tLoss: 1.754167\n",
      "Train Epoch: 44 [25600/60000 (43%)]\tLoss: 1.733447\n",
      "Train Epoch: 44 [32000/60000 (53%)]\tLoss: 1.726174\n",
      "Train Epoch: 44 [38400/60000 (64%)]\tLoss: 1.780040\n",
      "Train Epoch: 44 [44800/60000 (75%)]\tLoss: 1.713228\n",
      "Train Epoch: 44 [51200/60000 (85%)]\tLoss: 1.809696\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Train Epoch: 44 [57600/60000 (96%)]\tLoss: 1.764426\n",
      "\n",
      "Test set: Average loss: 0.0017, Accuracy: 6107/10000 (61%)\n",
      "\n",
      "Train Epoch: 45 [0/60000 (0%)]\tLoss: 1.792081\n",
      "Train Epoch: 45 [6400/60000 (11%)]\tLoss: 1.753014\n",
      "Train Epoch: 45 [12800/60000 (21%)]\tLoss: 1.667024\n",
      "Train Epoch: 45 [19200/60000 (32%)]\tLoss: 1.746590\n",
      "Train Epoch: 45 [25600/60000 (43%)]\tLoss: 1.713296\n",
      "Train Epoch: 45 [32000/60000 (53%)]\tLoss: 1.757093\n",
      "Train Epoch: 45 [38400/60000 (64%)]\tLoss: 1.746684\n",
      "Train Epoch: 45 [44800/60000 (75%)]\tLoss: 1.814887\n",
      "Train Epoch: 45 [51200/60000 (85%)]\tLoss: 1.688820\n",
      "Train Epoch: 45 [57600/60000 (96%)]\tLoss: 1.756308\n",
      "\n",
      "Test set: Average loss: 0.0017, Accuracy: 6156/10000 (62%)\n",
      "\n",
      "Train Epoch: 46 [0/60000 (0%)]\tLoss: 1.707843\n",
      "Train Epoch: 46 [6400/60000 (11%)]\tLoss: 1.656018\n",
      "Train Epoch: 46 [12800/60000 (21%)]\tLoss: 1.694059\n",
      "Train Epoch: 46 [19200/60000 (32%)]\tLoss: 1.726766\n",
      "Train Epoch: 46 [25600/60000 (43%)]\tLoss: 1.670163\n",
      "Train Epoch: 46 [32000/60000 (53%)]\tLoss: 1.750361\n",
      "Train Epoch: 46 [38400/60000 (64%)]\tLoss: 1.751065\n",
      "Train Epoch: 46 [44800/60000 (75%)]\tLoss: 1.718855\n",
      "Train Epoch: 46 [51200/60000 (85%)]\tLoss: 1.694813\n",
      "Train Epoch: 46 [57600/60000 (96%)]\tLoss: 1.635129\n",
      "\n",
      "Test set: Average loss: 0.0017, Accuracy: 6216/10000 (62%)\n",
      "\n",
      "Train Epoch: 47 [0/60000 (0%)]\tLoss: 1.597995\n",
      "Train Epoch: 47 [6400/60000 (11%)]\tLoss: 1.721132\n",
      "Train Epoch: 47 [12800/60000 (21%)]\tLoss: 1.632957\n",
      "Train Epoch: 47 [19200/60000 (32%)]\tLoss: 1.745734\n",
      "Train Epoch: 47 [25600/60000 (43%)]\tLoss: 1.671501\n",
      "Train Epoch: 47 [32000/60000 (53%)]\tLoss: 1.711395\n",
      "Train Epoch: 47 [38400/60000 (64%)]\tLoss: 1.665590\n",
      "Train Epoch: 47 [44800/60000 (75%)]\tLoss: 1.693355\n",
      "Train Epoch: 47 [51200/60000 (85%)]\tLoss: 1.664666\n",
      "Train Epoch: 47 [57600/60000 (96%)]\tLoss: 1.666185\n",
      "\n",
      "Test set: Average loss: 0.0017, Accuracy: 6271/10000 (63%)\n",
      "\n",
      "Train Epoch: 48 [0/60000 (0%)]\tLoss: 1.652541\n",
      "Train Epoch: 48 [6400/60000 (11%)]\tLoss: 1.652551\n",
      "Train Epoch: 48 [12800/60000 (21%)]\tLoss: 1.684919\n",
      "Train Epoch: 48 [19200/60000 (32%)]\tLoss: 1.758503\n",
      "Train Epoch: 48 [25600/60000 (43%)]\tLoss: 1.632286\n",
      "Train Epoch: 48 [32000/60000 (53%)]\tLoss: 1.654598\n",
      "Train Epoch: 48 [38400/60000 (64%)]\tLoss: 1.712298\n",
      "Train Epoch: 48 [44800/60000 (75%)]\tLoss: 1.684034\n",
      "Train Epoch: 48 [51200/60000 (85%)]\tLoss: 1.630519\n",
      "Train Epoch: 48 [57600/60000 (96%)]\tLoss: 1.658512\n",
      "\n",
      "Test set: Average loss: 0.0017, Accuracy: 6317/10000 (63%)\n",
      "\n",
      "Train Epoch: 49 [0/60000 (0%)]\tLoss: 1.642875\n",
      "Train Epoch: 49 [6400/60000 (11%)]\tLoss: 1.627908\n",
      "Train Epoch: 49 [12800/60000 (21%)]\tLoss: 1.683219\n",
      "Train Epoch: 49 [19200/60000 (32%)]\tLoss: 1.736090\n",
      "Train Epoch: 49 [25600/60000 (43%)]\tLoss: 1.722171\n",
      "Train Epoch: 49 [32000/60000 (53%)]\tLoss: 1.669616\n",
      "Train Epoch: 49 [38400/60000 (64%)]\tLoss: 1.598384\n",
      "Train Epoch: 49 [44800/60000 (75%)]\tLoss: 1.684112\n",
      "Train Epoch: 49 [51200/60000 (85%)]\tLoss: 1.686620\n",
      "Train Epoch: 49 [57600/60000 (96%)]\tLoss: 1.571283\n",
      "\n",
      "Test set: Average loss: 0.0016, Accuracy: 6365/10000 (64%)\n",
      "\n",
      "Train Epoch: 50 [0/60000 (0%)]\tLoss: 1.655643\n",
      "Train Epoch: 50 [6400/60000 (11%)]\tLoss: 1.611854\n",
      "Train Epoch: 50 [12800/60000 (21%)]\tLoss: 1.660793\n",
      "Train Epoch: 50 [19200/60000 (32%)]\tLoss: 1.638171\n",
      "Train Epoch: 50 [25600/60000 (43%)]\tLoss: 1.739760\n",
      "Train Epoch: 50 [32000/60000 (53%)]\tLoss: 1.698681\n",
      "Train Epoch: 50 [38400/60000 (64%)]\tLoss: 1.675967\n",
      "Train Epoch: 50 [44800/60000 (75%)]\tLoss: 1.646864\n",
      "Train Epoch: 50 [51200/60000 (85%)]\tLoss: 1.590694\n",
      "Train Epoch: 50 [57600/60000 (96%)]\tLoss: 1.615242\n",
      "\n",
      "Test set: Average loss: 0.0016, Accuracy: 6418/10000 (64%)\n",
      "\n"
     ]
    }
   ],
   "source": [
    "for epoch in range(1, 51):\n",
    "    train(model, device, train_loader, optimizer, epoch)\n",
    "    test(model, device, test_loader)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.21"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
